package com.promise.jokerdream.ui.settings

import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.promise.jokerdream.database.entity.ConstellationGameConfigEntity
import com.promise.jokerdream.model.constellation.ConstellationMapping
import com.promise.jokerdream.ui.components.SettingCard
import com.promise.jokerdream.ui.components.SingleSelectHashtagBottomSheet
import com.promise.jokerdream.ui.components.SelectionRow
import com.promise.jokerdream.ui.theme.AppFontSizes

/**
 * 十二宫设置卡片
 */
@Composable
fun ConstellationSettingCard(
    // 十二宫相关
    config: ConstellationGameConfigEntity,
    onConstellationChange: (Boolean) -> Unit,
    onConstellationTextChange: (String) -> Unit,
    
    modifier: Modifier = Modifier,
    onExecuteClick: (() -> Unit)? = null
) {
    SettingCard(
        title = "十二宫",
        description = "",
        checked = config.enabledSetting,
        onCheckedChange = onConstellationChange,
        modifier = modifier,
        onExecuteClick = onExecuteClick,
        content = {
            if (config.enabledSetting) {
                // 十二宫选择区域
                ConstellationSelectionArea(
                    selectedConstellationText = config.levelName,
                    onConstellationTextChange = onConstellationTextChange
                )
            }
        }
    )
}

/**
 * 十二宫选择区域
 */
@Composable
private fun ConstellationSelectionArea(
    selectedConstellationText: String,
    onConstellationTextChange: (String) -> Unit
) {
    var showBottomSheet by remember { mutableStateOf(false) }
    val selectedConstellationFormat = selectedConstellationText.ifEmpty { "未选择" }
    val recommendedTags = ConstellationMapping.getAllIdNameFormats()

    SelectionRow(
        label = "当前副本：",
        selectedText = selectedConstellationFormat,
        onClick = { showBottomSheet = true }
    )

    // 半浮层
    if (showBottomSheet) {
        SingleSelectHashtagBottomSheet(
            title = "选择十二宫",
            initialText = selectedConstellationFormat,
            placeholder = "支持输入1000或1000-白羊宫",
            recommendedTags = recommendedTags,
            onCancel = { showBottomSheet = false },
            onDismiss = { showBottomSheet = false},
            onComplete = { selectedFormat ->
                onConstellationTextChange(selectedFormat)
                showBottomSheet = false
            }
        )
    }
}
